<?php // no direct access
defined('_JEXEC') or die('Restricted access');

if (!function_exists('filternewslettersmarttext')) {
  include('administrator/components/com_nspro/lib.php');
}

$show_id = $this->show_id;
$show_subject = $this->show_subject;
$show_datetime = $this->show_datetime;

?>
<div class="nspro componentheading"><?php print JText::_('Newsletter View'); ?></div><br/>
<?php

$db =& JFactory::getDBO();

$query = 'SELECT * FROM `#__nspro_newsletter_attachments` AS atm LEFT JOIN `#__nspro_newsletters` AS ns ON atm.newsletter_id=ns.id WHERE ns.sent="1" ORDER BY atm.id';
$db->setQuery($query);
$mattachments = $db->loadObjectList();

$db->setQuery('SELECT * FROM `#__nspro_newsletters` WHERE `sent` = "1"');
$mNewsletters = $db->loadObjectList();

if (count($mNewsletters) > 0) {
  $found = false;
  foreach ($mNewsletters as $mnl) {
    if ($mnl->id == $_GET['nid']) {
      $found = true;
      print '<table cellpadding="2" border="0" class="nspro nsprotable" id="nsprotableview">';
      if ($show_id == true) {
        print '<tr style="border:none;"><td style="border:none; padding: 2px;">' . JText::_('ID') . '</td><td style="border:none; padding: 2px;">' . $mnl->id . '</td></tr>';
      }
      if ($show_subject == true) {
        print '<tr style="border:none;"><td style="border:none; padding: 2px;">' . JText::_('Subject') . '</td><td style="border:none; padding: 2px;">' . $mnl->subject . '</td></tr>';
      }
      if ($show_datetime == true) {
        print '<tr style="border:none;"><td style="border:none; padding: 2px;">' . JText::_('Date and Time Sent') . '</td><td style="border:none; padding: 2px;">' . $mnl->datetime . '</td></tr>';
      }

      if (isset($_GET['semail'])) {
        $mysub = GetSubFromEmail($_GET['semail']);
        $mMessage = FilterNewsletterSmartText($mysub->name, $mysub->email, $mnl->id, $mnl->message, $mysub->id);
      }
      else {
        $mMessage = FilterNewsletterSmartText('Guest', 'Guest Email', $mnl->id, $mnl->message, 0);
      }
      print '<tr style="border:none;"><td valign="top" style="border:none; padding: 2px;">' . JText::_('Message') . '</td><td style="border:none; padding: 2px;"><div id="nspro_message">' . $mMessage . '</div></td></tr>';
      print '</table>';
      break;
    }
  }
  if (!$found) {
    print JText::_('No Newsletter found.');
  }
}
else {
  print JText::_('No Newsletters found.');
}

?>

